package KMP;

public class ForceStr {
    //暴力破解字符串匹配问题
    public static int forceKmp(String mainStr,String findStr){
        //主串指针
        int i = 0;
        //目标串指针
        int j = 0;

        char[] mainStrs = mainStr.toCharArray();
        char[] findStrs = findStr.toCharArray();

        while (i<mainStrs.length&&j<findStrs.length){
            if(mainStrs[i]==findStrs[j]){
                i++;
                j++;
            }else {
                i = i - j +1;
                j=0;
            }
        }
        if( j == findStrs.length ){
            return i - j;
        }

        return -1;
    }

    public static void main(String[] args) {
        String mainStr = "aaaabcd";
        String findStr = "abcd";
        System.out.println(forceKmp(mainStr,findStr));
    }

}
